import {fileURLToPath, URL} from 'node:url'

import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
import {createHtmlPlugin} from "vite-plugin-html";
import {settings} from "./src/settings.js";
import path from 'path'

const getTarget = (mode, target) => {
    return loadEnv(mode, process.cwd())[target]
}

export default ({mode}) => defineConfig({
    define: {
        __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true
    },
    server: {
        port: 8888,
        open: false,

    },
    plugins: [
        vue(),
        createSvgIconsPlugin({
            iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
            symbolId: '[name]'
        }),
        createHtmlPlugin({
            inject: {
                data: {
                    title: settings.title || getTarget(mode, 'VITE_APP_TITLE')
                }
            }
        })
    ],

    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    }
})
